        var runCostStore = new Ext.data.JsonStore({
			url: '/weihe/getList_runCost',
			root: 'datas',
			fields : [{
						name:'RuncostId',mapping:'id'
					},{
     				   name:'RuncostDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
      			  	},{
						name:'RuncostBuySum',mapping:'buySum'
					},{
						name:'RuncostFreight',mapping:'freight'
					},{
						name:'RuncostInsure',mapping:'insure'
				    },{
				    	name:'RuncostCard',mapping:'card'
				    },{
				    	name:'RuncostCustoms',mapping:'customs'
				    },{
				    	name:'RuncostStack',mapping:'stack'
				    },{
				    	name:'RuncostTrailer',mapping:'trailer'
				    },{
				    	name:'RuncostElec',mapping:'elec'
				    },{
				    	name:'RuncostSeal',mapping:'seal'
				    },{
				    	name:'RuncostArk',mapping:'ark'
				    },{
				    	name:'RuncostPresscar',mapping:'presscar'
				    },{
				    	name:'RuncostBonus',mapping:'bonus'
				    },{
				    	name:'RuncostOthers',mapping:'others'
				    },{
				    	name:'RuncostSum',mapping:'sum'
				    }],
						listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_runCost',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
        
        
        var rcStore = new Ext.data.JsonStore({
			url: '/weihe/getItems_runCost',
			root: 'datas',
			fields : [{
						name:'RuncostId',mapping:'id'
					},{
     				   name:'RuncostDate', mapping:'date',type : 'date', dateFormat:"Y-m-d"
      			  	},{
						name:'RuncostCount',mapping:'count'
					},{
						name:'RuncostPrice',mapping:'price'
					},{
						name:'RuncostBuySum',mapping:'buySum'
					},{
						name:'RuncostFreight',mapping:'freight'
					},{
						name:'RuncostInsure',mapping:'insure'
				    },{
				    	name:'RuncostCard',mapping:'card'
				    },{
				    	name:'RuncostCustoms',mapping:'customs'
				    },{
				    	name:'RuncostStack',mapping:'stack'
				    },{
				    	name:'RuncostTrailer',mapping:'trailer'
				    },{
				    	name:'RuncostElec',mapping:'elec'
				    },{
				    	name:'RuncostSeal',mapping:'seal'
				    },{
				    	name:'RuncostArk',mapping:'ark'
				    },{
				    	name:'RuncostPresscar',mapping:'presscar'
				    },{
				    	name:'RuncostBonus',mapping:'bonus'
				    },{
				    	name:'RuncostOthers',mapping:'others'
				    },{
				    	name:'RuncostSum',mapping:'sum'
				    }],
						listeners :{ 
					   'beforeload':function(s,options) {
							var tag = 0;
							Ext.Ajax.request({
								url : '/weihe/getListJudge_runCost',
								success : function(response) {
									var json = Ext.decode(response.responseText);
									if (json.deny) {
										Ext.Msg.alert('错误',json.msg);
										tag = 1;
									}
										if(tag == 1){
											return false;
										}else{
											return true;						
										}
								},
								failure : function() {
									Ext.Msg.alert('错误', '失败!');
									tag =1;
								}
							});
			   }
			}
		});
    	
    	

runCosts = function(){
  return{
     
	  rcGrid : function(){

		var pageToolBar = new Ext.PagingToolbar({
			pageSize : 5,
			store : rcStore,
			displayInfo : true,
			displayMsg : '当前显示{0}-{1}条记录,共{2}条记录',
		    emptyMsg : "没有记录显示!",
		    firstText : '首页',
		    prevText : '上一页',
		    nextText : '下一页',
		    lastText : '尾页',
		    beforePageText : '第',
		    afterPageText : '页,共{0}页'
		   
		});

	

		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		 
	   var rcGrid = new Ext.grid.GridPanel({
		   id:'rcGrid',
		   title : '经营成本表',
		   region : 'center',
		   minColumnWidth : 50,
		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : rcStore,
		   columns: [
		             {header : '日期', dataIndex : 'RuncostDate', menuDisabled : true,renderer:function(value){return value.format('Y年m月');}},
		             {header : '购入数量', dataIndex : 'RuncostCount'},
		             {header : '购入均价', dataIndex : 'RuncostPrice'},
		             {header : '购入金额', dataIndex : 'RuncostBuySum'},
		             {header : '运费', dataIndex : 'RuncostFreight'},
		             {header : '保险', dataIndex : 'RuncostInsure'},
		             {header : '换证', dataIndex : 'RuncostCard'},
		             {header : '报关', dataIndex : 'RuncostCustoms'},
		             {header : '堆存', dataIndex : 'RuncostStack'},
		             {header : '拖车', dataIndex : 'RuncostTrailer'},
		             {header : '电放', dataIndex : 'RuncostElec'},
		             {header : '封条', dataIndex : 'RuncostSeal'},
		             {header : '购柜', dataIndex : 'RuncostArk'},
		             {header : '压车', dataIndex : 'RuncostPresscar'},
		             {header : '业务提成', dataIndex : 'RuncostBonus'},
		             {header : '其他', dataIndex : 'RuncostOthers'},
		             {header : '本月合计', dataIndex : 'RuncostSum'}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
				   Ext.getCmp("runCostForm").form.loadRecord(record);
				   var d = record.get('RuncostDate').format('Y-m')+"";
				   Ext.getCmp("runCostForm").form.findField('sd').setValue(d);
				   Ext.getCmp("runCostForm").buttons[0].setText('修改');
		   }
		},
		  viewConfig : {
		     forceFit : false
		  },
		  bbar : pageToolBar
});
		return rcGrid;
	},
	 runCostGrid : function(){



		var rowSelectionModel = new Ext.grid.RowSelectionModel({singleSelect : true});
		
		 
	   var runCostGrid = new Ext.grid.GridPanel({
		   id:'runCostGrid',
		   title : '经营成本统计表',
		   region : 'north',
		   height :300,
		   minColumnWidth : 50,
		   tbar:["-",'查看年份:',new Ext.form.TextField({id:'year',name:'query',value:(new Date()).format('Y'),width:'50'}),new Ext.Button({text:'提交',handler : function() {
			   					Ext.getCmp("runCostGrid").getStore().baseParams = {'query':Ext.getCmp('year').getValue()};
			   					Ext.getCmp("runCostGrid").getStore().load({params : {start : 0, limit : 13}});
			   					Ext.getCmp("rcGrid").getStore().removeAll();
		   		}})
		   ,"-"],

		   loadMask : {msg:'正在加载数据，请稍侯...'},
		   store : runCostStore,
		   columns: [
		             {header : '日期', dataIndex : 'RuncostDate', menuDisabled : true,renderer:function(value){
							if(value != null){
									return value.format('Y年m月');
								}else{
									return '本年累计';
								}
		             }},
		             {header : '购入金额', dataIndex : 'RuncostBuySum'},
		             {header : '运费', dataIndex : 'RuncostFreight'},
		             {header : '保险', dataIndex : 'RuncostInsure'},
		             {header : '换证', dataIndex : 'RuncostCard'},
		             {header : '报关', dataIndex : 'RuncostCustoms'},
		             {header : '堆存', dataIndex : 'RuncostStack'},
		             {header : '拖车', dataIndex : 'RuncostTrailer'},
		             {header : '电放', dataIndex : 'RuncostElec'},
		             {header : '封条', dataIndex : 'RuncostSeal'},
		             {header : '购柜', dataIndex : 'RuncostArk'},
		             {header : '压车', dataIndex : 'RuncostPresscar'},
		             {header : '业务提成', dataIndex : 'RuncostBonus'},
		             {header : '其他', dataIndex : 'RuncostOthers'},
		             {header : '本月合计', dataIndex : 'RuncostSum'}
        ],
           sm : rowSelectionModel,
           listeners :{ 
			   'rowclick':function(grid, rowIndex, event) {
			   var record = grid.getStore().getAt(rowIndex);
			   if(record.get('RuncostDate')!=null){
			  	 var d = record.get('RuncostDate').format('Y-m')+"";
			  	 Ext.getCmp("rcGrid").getStore().baseParams = {'sd':d};
			   	 Ext.getCmp("rcGrid").getStore().load({params : {start : 0, limit : 5}});
			   	}
			   }
		   
		},
		  viewConfig : {
		     forceFit : false
		  }
});
		return runCostGrid;
	},
	runCostForm : function(){
		var button_add = new Ext.Button({
			text : '添加',
			handler : function() {
					progressConsole();
				if(runCostForm.form.isValid()){ 	
					if (runCostForm.form.findField("runCost.id").getValue() == "") {
						runCostForm.form.submit({
						  url : '/weihe/add_runCost',
						   success : function(form, action) {
							  if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
								Ext.Msg.alert('消息', action.result.msg, function() {
									   Ext.getCmp("rcGrid").getStore().baseParams = {'sd':runCostForm.form.findField('sd').getValue()};
									   runCostForm.form.reset();
									   Ext.getCmp("rcGrid").getStore().load({params : {start : 0, limit : 5}});
									   Ext.getCmp("runCostGrid").getStore().load({params : {start : 0, limit : 13}});
								});
							  }
						    }
					    });
					}else {
						runCostForm.form.submit({
							  url : '/weihe/update_runCost',
							   success : function(form, action) {
								  if (action.result.deny) {
									 Ext.Msg.alert('错误', action.result.msg);
								  }else{
									Ext.Msg.alert('消息', action.result.msg, function() {
										runCostForm.form.reset();
										Ext.getCmp("rcGrid").getStore().reload();
										 Ext.getCmp("runCostGrid").getStore().reload();
										runCostForm.buttons[0].setText('添加');
										
									});
								  }
							    }
						    });
					}
			}else{
				Ext.Msg.alert('提示','请输入相关内容');
			}
				}
		
			
		});

	var button_clear = new Ext.Button({
		id : 'button_clear',
		text : '清空',
		handler : function() {
			runCostForm.form.reset();
			runCostForm.buttons[0].setText('添加');
		}
	});

	var button_del = new Ext.Button({
		text : '删除',
		handler : function() {
			var id = runCostForm.form.findField('runCost.id').getValue();
			if (id == '') {
				Ext.Msg.alert('提示', '请选择需要删除的信息!');
			} else {
				progressConsole();
				Ext.Ajax.request({
					url : '/weihe/delete_runCost',
					success : function(response) {
						var json = Ext.decode(response.responseText);
						if (json.success) {
							if (json.deny) {
								Ext.Msg.alert('消息', json.msg);
								runCostForm.form.reset();
								runCostForm.buttons[0].setText('添加');
						 	}else{
							Ext.Msg.alert('消息', json.msg, function() {
								Ext.getCmp("runCostGrid").getStore().load({params : {start : 0, limit : 13}});
								Ext.getCmp("rcGrid").getStore().reload();
								runCostForm.form.reset();
								runCostForm.buttons[0].setText('添加');
							});
						 	}
						}else{
							Ext.Msg.alert('消息', json.msg);
						}
					},
					failure : function() {
						Ext.Msg.alert('错误', '删除失败!');
					},
					params : 'runCost.id=' + id
				});
			}
		}
	});
	

	

	var  runCostForm = new Ext.form.FormPanel({
		id : 'runCostForm',
		title : '费用信息',
		frame : true,
		width : 300,
		region : 'east',
		autoScroll : true,
		labelAlign : 'right',
		labelWidth : 60,
		defaultType : 'textfield',
			defaults : {
			width : 200
		},
		items : [{  
			id:'RuncostId',
			xtype : 'hidden',  
			name : 'runCost.id'
		},{
			id:'RuncostDate',
			fieldLabel : '日期',
			name : 'sd',
			regex : /^\d{4}-(?:0[1-9]|1[0-2])$/,
		    regexText:'请输入有效日期格式为2010-01' 
		},{
			id:'RuncostCount',
			fieldLabel : '购入数量',
			name : 'runCost.count'
		},{
			id:'RuncostPrice',
			fieldLabel : '购入均价',
			name : 'runCost.price',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostFreight',
			fieldLabel : '运费',
			name : 'runCost.freight',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostInsure',
			fieldLabel : '保险',
			name : 'runCost.insure',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostCard',
			fieldLabel : '换证',
			name : 'runCost.card',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostCustoms',
			fieldLabel : '报关',
			name : 'runCost.customs',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostStack',
			fieldLabel : '堆存',
			name : 'runCost.stack',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostTrailer',
			fieldLabel : '拖车',
			name : 'runCost.trailer',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostElec',
			fieldLabel : '电放',
			name : 'runCost.elec',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostSeal',
			fieldLabel : '封条',
			name : 'runCost.seal',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostArk',
			fieldLabel : '购柜',
			name : 'runCost.ark',
			regex : /^-?\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostPresscar',
			fieldLabel : '压车',
			name : 'runCost.presscar',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostBonus',
			fieldLabel : '业务提成',
			name : 'runCost.bonus',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		},{
			id:'RuncostOthers',
			fieldLabel : '其他',
			name : 'runCost.others',
			regex : /^\d+(\.\d+)?$/,
		    regexText:'请输入有效的价格' 
		}],
		buttons : [button_add,button_clear,button_del]
	});
		return  runCostForm;
	}
  }
}();








